package com.ssm.gbq.dao.impl;

import com.ssm.gbq.dao.DoctorDao;
import com.ssm.gbq.mapper.DoctorMapper;
import com.ssm.gbq.model.Doctor;
import com.ssm.gbq.model.vo.NameDto;
import gbq.ssm.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DoctorDaoImpl implements DoctorDao {

    @Autowired
    private DoctorMapper doctorMapper;

    public PageBounds<Doctor> openDoctorTable(String nameOrPhone, int currentPage, int pageSize) {
        final int totalSize = doctorMapper.countByExample(nameOrPhone);
        PageBounds<Doctor> pageBounds = new PageBounds<Doctor>(currentPage, totalSize, pageSize);
        List<Doctor> list = doctorMapper.selectByLimitPage(nameOrPhone, pageBounds.getOffset(), pageBounds.getPageSize());
        pageBounds.setPageList(list);
        return pageBounds;
    }

    public Doctor getDoctorById(Integer id) {
        return doctorMapper.selectByPrimaryKey(id);
    }

    public List<Doctor> searchDoctor(String nameOrPhone) {
        return doctorMapper.searchDoctor(nameOrPhone);
    }

    public List<Doctor> getDoctorByDepartment(Integer id) {
        return null;
    }

    public void addDoctor(Doctor doctor) {
        doctorMapper.insert(doctor);
    }

    public void delDoctorById(List<Integer> ids) {
        doctorMapper.deleteByPrimaryKey(ids);
    }

    public void updateDoctor(Doctor doctor){
        doctorMapper.updateByPrimaryKeySelective(doctor);
    }

}
